<?php
// 应用公共文件

function res($code,$msg,$data = [],$count = ''){
    if($count == '') {
        return json_encode(compact('code', 'msg', 'data'));
    }
    return json_encode(compact('code', 'count','msg', 'data'));
}


function encrypt($str){

}

function decrypt($str){

}

function getNowUserId(){
    $user = json_decode(session("contact_user"),true);
    return $user["user_id"];
}



function checkNull($data){
    if($data == null){
        return false;
    }
    return true;
}
function get_constellation($mydate,$symbol='-'){

    //计算年龄
    $birth=$mydate;
    list($by,$bm,$bd)=explode($symbol,$birth);
    $cm=date('n');
    $cd=date('j');
    $age=date('Y')-$by-1;
    if ($cm>$bm || $cm==$bm && $cd>$bd) $age++;
    $array['age'] = $age;
    //计算生肖
    $animals = array(
        '鼠', '牛', '虎', '兔', '龙', '蛇',
        '马', '羊', '猴', '鸡', '狗', '猪'
    );
    $key = ($by - 1900) % 12;
    $array['animals'] = $animals[$key];

    //计算星座
    $constellation_name = array(
        '水瓶座','双鱼座','白羊座','金牛座','双子座','巨蟹座',
        '狮子座','处女座','天秤座','天蝎座)','射手座','摩羯座'
    );
    if ($bd <= 22){
        if ('01' !== $bm) $constellation = $constellation_name[$bm-2]; else $constellation = $constellation_name[11];
    }else $constellation = $constellation_name[$bm-1];
    $array['constellation'] = $constellation;

    return $array;
}
define('MSG_NOT_POST','请求方式错误');
define('MSG_NOT_KEY','错误无标识');
define('MSG_FAIL','操作失败');
define('MSG_SUCCESS','操作成功');
define('MSG_PARAM','参数不完整');
define('MSG_PARAMFAIL','参数错误');

